package com.pocket.cloud.common.api;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author zhaozhile
 */
@Data
@Accessors(chain = true)
public class ResultData<T>
{

    /**
     * {@link ReturnCodeEnum}
     */
    private String code;
    private String message;
    private T data;
    private long timestamp;
    private String errorDetails;

    public ResultData() {
    }

    public ResultData(ReturnCodeEnum codeEnum, T data, String errorDetails) {
        this.code = codeEnum.getCode();
        this.message = codeEnum.getMessage();
        this.data = data;
        this.timestamp = System.currentTimeMillis();
        this.errorDetails = errorDetails;
    }

    public static <T> ResultData<T> success(T data)
    {
        return new ResultData<>(ReturnCodeEnum.RC200, data, null);
    }

    public static <T> ResultData<T> fail(ReturnCodeEnum codeEnum)
    {
        return fail(codeEnum, null);
    }

    public static <T> ResultData<T> fail(ReturnCodeEnum codeEnum, String errorDetails)
    {
        return new ResultData<>(codeEnum, null, errorDetails);
    }
}
